<HTML>
<HEAD>
<TITLE>
LocalLibrary.cpp
</TITLE>
</HEAD>
<BODY>
<PRE>
<font color="green">/*
* Copyright 2006 the original author or authors.
* 
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* 
*      http://www.apache.org/licenses/LICENSE-2.0
* 
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/</font>

<font color="blue">#include</font> <font color="maroon">&#60;string&#62;</font>
<font color="blue">#include</font> <font color="maroon">"AutumnException.h"</font>
<font color="blue">#include</font> <font color="maroon">"LocalLibrary.h"</font>

<font color="blue">namespace</font> Autumn<font color="black">{</font>

LocalLibrary<font color="black">*</font> LocalLibrary<font color="black">:</font><font color="black">:</font>instance <font color="black">=</font> NULL;

LocalLibrary<font color="black">*</font> LocalLibrary<font color="black">:</font><font color="black">:</font>getInstance<font color="black">(</font><font color="black">)</font>
<font color="black">{</font>
    <font color="blue">if</font><font color="black">(</font> LocalLibrary<font color="black">:</font><font color="black">:</font>instance <font color="black">=</font><font color="black">=</font> NULL<font color="black">)</font>
        LocalLibrary<font color="black">:</font><font color="black">:</font>instance <font color="black">=</font> <font color="blue">new</font> LocalLibrary<font color="black">(</font><font color="black">)</font>;
    <font color="blue">return</font> LocalLibrary<font color="black">:</font><font color="black">:</font>instance;
<font color="black">}</font>

<font color="blue">void</font> LocalLibrary<font color="black">:</font><font color="black">:</font>addFunction<font color="black">(</font><font color="blue">const</font> <font color="blue">char</font><font color="black">*</font> <font color="blue">name</font>, <font color="blue">void</font><font color="black">*</font> fun<font color="black">)</font>
<font color="black">{</font>
    <font color="blue">this</font><font color="black">-</font><font color="black">&#62;</font>LocalFunctions.insert<font color="black">(</font>make_pair<font color="black">(</font>string<font color="black">(</font><font color="blue">name</font><font color="black">)</font>, fun<font color="black">)</font><font color="black">)</font>;
<font color="black">}</font>

<font color="blue">void</font><font color="black">*</font> LocalLibrary<font color="black">:</font><font color="black">:</font>getFunction<font color="black">(</font><font color="blue">const</font> string<font color="black">&</font> <font color="blue">name</font><font color="black">)</font><font color="blue">const</font>
<font color="black">{</font>
    map<font color="black">&#60;</font>string, <font color="blue">void</font><font color="black">*</font><font color="black">&#62;</font><font color="black">:</font><font color="black">:</font>const_iterator it<font color="black">=</font><font color="blue">this</font><font color="black">-</font><font color="black">&#62;</font>LocalFunctions.find<font color="black">(</font><font color="blue">name</font><font color="black">)</font>;
    <font color="blue">if</font><font color="black">(</font> it <font color="black">!</font><font color="black">=</font> <font color="blue">this</font><font color="black">-</font><font color="black">&#62;</font>LocalFunctions.end<font color="black">(</font><font color="black">)</font> <font color="black">)</font>
        <font color="blue">return</font> it<font color="black">-</font><font color="black">&#62;</font>second;
    <font color="blue">throw</font> NotFoundEx<font color="black">(</font><font color="maroon">"LocalLibrary"</font>, <font color="maroon">"getFunction"</font>, 
        <font color="maroon">"function ["</font> <font color="black">+</font> <font color="blue">name</font> <font color="black">+</font> <font color="maroon">"] not found!"</font><font color="black">)</font>;
<font color="black">}</font>

<font color="black">}</font> <font color="green">// End namespace Autumn</font>

</PRE>
</BODY>
</HTML>
